package com.atguigu.flink.chapter11;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

/**
 * @Author lzc
 * @Date 2022/10/31 10:41
 */
public class Flink06_SQL_File {
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(2);
        
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
        
        // 建立一张表与文件关联: ddl(建表语句)
        String sql = "create table sensor(" +
            "id string, " +
            "ts bigint, " +
            "vc int" +
            ")with(" +
            " 'connector' = 'filesystem', " +
            " 'path' = 'input/sensor.txt', " +
            " 'format' = 'csv' " +
            ")";
        System.out.println(sql);
        tEnv.executeSql(sql);
    
        Table result = tEnv.sqlQuery("select * from sensor where id='sensor_1'");
        
        tEnv.executeSql("create table abc(" +
                            "id string, " +
                            "ts bigint, " +
                            "vc int" +
                            ")with(" +
                            " 'connector' = 'filesystem', " +
                            " 'path' = 'input/b.txt', " +
                            " 'format' = 'csv' " +
                            ")");
        result.executeInsert("abc");
    
    }
}
/*
TableApi

SQL

 */